//json
//车垱信息
function main(tbl){
	let tab1=new JseMap();
	
	if(isEmpty(tbl.hphm)||tbl.hphm.length<5){
		return {code:1101,msg:"请输入正确车牌号"}
	}else{
		let hphm=tbl.hphm;
		tab1.put("hphm",hphm)
	}
	if(isEmpty(tbl.hpzl)){
		return {code:1101,msg:"号牌种类不能为空"}
	}else{
		tab1.put("hpzl",tbl.hpzl)
	}
	if(isEmpty(tbl.fdjh)){
		return {code:1101,msg:"发动机号不能为空"}
	}else{
		tab1.put("fdjh",tbl.fdjh)
	}
	if(isEmpty(tbl.cjh)){
		return {code:1101,msg:"车架号不能为空"}
	}else{
		tab1.put("cjh",tbl.cjh)
	}
	let u=attr("u")
	let lang="en";
	if(!isEmpty(tbl.lang)){
		lang=tbl.lang;
	}
	let time1=System.currentTimeMillis();
	let res={}
	let reqres="请求成功"
	let resmsg="查询成功"
	let tb=dao.fetch("wz_v1",Cnd.where("tbl","=",tab1.tourl()))
	let key="HxZZ1onq7Swu9F3iY0M8_0ZiztIjCoNz";
	if(tb!=null){
		res= baozhuang(tb.result,lang,tbl.name);
	}else{
		let text=Http.get(`http://47.97.111.182/wz/query?hphm=${tab1.hphm}&hpzl=${tab1.hpzl}&fdjh=${tab1.fdjh}&cjh=${tab1.cjh}&key=${key}`);
		res=foJson(text);
		print(res.code==1008)
		if(res.code==1007||res.code==1008||res.code==1009){
			resmsg="查询成功"
				//res.code=200;
				res=baozhuang(res,lang,tbl.name);
				let tab=new Record();
				tab.put(".table","car_info")
				tab.put("type","违章v1")
				tab.put("tbl",tab1.tourl())
				tab.put("result",text)
				dao.insert(tab)
			
		}else{
			resmsg="查无数据"
//			res.code=404;
			res.msg=resmsg;
		}
	}
	let time2=System.currentTimeMillis();
	let time3=(time2-time1)+1;
	let tab=new Record();
	tab.put(".table","app_log")
	tab.put("username",u.username)
	tab.put("ms",time3)
	tab.put("uid",u.id)
	tab.put("type",u.type)
	tab.put("ip",ip())
	tab.put("reqres",reqres)
	tab.put("resmsg",resmsg)
	tab.put("param",tbl.tourl())
	$save(tab)
	if(resmsg=="查询成功"){
		$update({".table":"app_buy","cxnum":u.cxnum+1,"id":u.bid})
	}
	
	return res;
}
var dicts={"code":"状态码"}
function baozhuang(res,lang,name){
	if(isEmpty(res.code)){
		res.code=200;
	}
	if(lang=="cn"){
		let resmp1=new JseMap();
	for(var item in res.result){
		if(dicts[item]!=null){
			resmp1.put(dicts[item],res.result[item])
		}else{
			resmp1.put(item,res.result[item])
		}
	}
		res.result=resmp1;
	}
	return res;
}